package com.lt.test.provider.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.lt.test.api.CountService;
import com.lt.test.api.ShopService2;
import com.lt.test.common.emchat.Emchat;
import com.lt.test.common.exception.CustomException;
import com.lt.test.common.util.StringUtils;
import com.lt.test.entity.DTO.PageDTO;
import com.lt.test.provider.mapper.Shop2Mapper;
import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@Service(version = "1.0.0")
public class ShopService2Impl implements ShopService2 {
    private static final Logger logger = LoggerFactory.getLogger(ShopService2Impl.class);
    @Autowired
    private Shop2Mapper shop2Mapper;
    @Autowired
    private CountService countService;

    @Override
    public List<Map<String, Object>> selectDaZhuanPanPrizeToSelected() {
        return shop2Mapper.selectDaZhuanPanPrizeToSelected();
    }

    @Override
    public String bankMaintain(Map<String, String> parameter) throws Exception {
        String result;
        Map<String, Object> info = shop2Mapper.checkIsMaintain(parameter.get("custCode"));
        if (info != null) {
            result = parameter.get("custCode") + "收单行已经维护过";
        } else {
           // disposeBankMaintainParams(parameter);
            shop2Mapper.insertMaintainInfo(parameter);
            result = "维护成功";
        }
        return result;
    }

    private void disposeBankMaintainParams(Map<String, Object> parameter) throws CustomException {
        String bankMerCode;
        String areaCode;
        switch (parameter.get("bankCode").toString()) {
            case "YYT3017":
                bankMerCode = "100702044580010";
                areaCode = "0858";
                break;
            case "YYT3002":
                bankMerCode = "103520244589709";
                areaCode = "0858";
                break;
            default:
                throw new CustomException("没有找到银行信息");
        }
        parameter.put("bankMerCode", bankMerCode);
        parameter.put("areaCode", areaCode);
    }

    @Override
    public List<Map<String, Object>> getMain1Data(Map<String, String> stringMap) {
        try {
            return shop2Mapper.getMain1Data(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取卷烟统计数据失败：各县区销量、金额、消费次数");
        }
        return null;
    }


    @Override
    public List<Map<String, Object>> getMain2Data(Map<String, String> stringMap) {
        try {
            return shop2Mapper.getMain2Data(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取卷烟统计数据失败：前15名规格：销量、消费次数");
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> getMain3Data(Map<String, String> stringMap) {
        try {
            return shop2Mapper.getMain3Data(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取卷烟统计数据失败：前5品牌的时段统计");
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> getMain4Data(Map<String, String> stringMap) {
        try {
            return shop2Mapper.getMain4Data(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取卷烟统计数据失败：重点品牌、贵烟、低焦、细支、雪茄的销量、金额、消费次数");
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> getMain5Data(Map<String, String> stringMap) {
        try {
            return shop2Mapper.getMain5Data(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取卷烟统计数据失败：五类烟的销量、金额、消费次数");
        }
        return null;
    }

    @Override
    public PageDTO<Map<String, String>> getAogListByPageQuery(Map<String, String> stringMap) throws CustomException {
        Integer pageSize = 10;
        Long page = stringMap.get("page") == null ? 1 : Long.valueOf(stringMap.get("page"));
        Long beginNum = ((page - 1) * pageSize + 1);
        Long endNum = beginNum + pageSize - 1;

        stringMap.put("beginNum", beginNum.toString());
        stringMap.put("endNum", endNum.toString());

        List<Map<String, String>> list = null;
        try {
            list = shop2Mapper.getAogListByPageQuery(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("分页获取配送数据失败");
        }
        int recordCount = 0;
        try {
            recordCount = shop2Mapper.getAogListCountByPageQuery(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("分页获取配送总数失败");
        }
        PageDTO<Map<String, String>> result = new PageDTO<>(page.intValue(), pageSize, list, recordCount);
        return result;
    }

    @Override
    public List<Map<String, String>> getUserLocation(Map<String, String> params) {
        return shop2Mapper.getUserLocation(params);
    }

    @Override
    public Map<String, List<Map<String, Object>>> getCourierSelectData(Map<String, String> stringMap) {
        Map<String, List<Map<String, Object>>> result = new HashMap<>();
        try {
            List<Map<String, Object>> couriers = shop2Mapper.getCouriersToSelect(stringMap);
            result.put("couriers", couriers);
        } catch (Exception e) {
            logger.warn("获取物流员用于查询失败");
            e.printStackTrace();
        }
      /*  try {
            List<Map<String, Object>> drivers = shop2Mapper.getDriversToSelect();
            result.put("drivers", drivers);
        } catch (Exception e) {
            logger.warn("获取驾驶员用于查询失败");
            e.printStackTrace();
        }*/
        try {
            List<Map<String, Object>> licenses = shop2Mapper.getLicensesToSelect(stringMap);
            result.put("licenses", licenses);
        } catch (Exception e) {
            logger.warn("获取车辆用于查询失败");
            e.printStackTrace();
        }

        if (StringUtils.isNot_NullOrTrimEmpty(stringMap.get("time"))) {
            try {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date d = simpleDateFormat.parse(stringMap.get("time"));
                Calendar ca = Calendar.getInstance();
                ca.setTime(d);
                ca.add(Calendar.DATE, -2);
                Date firstDay = ca.getTime();
                SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
                String date = sf.format(firstDay);

                //stringMap.put("orderTime", date);
                List<Map<String, Object>> paths = shop2Mapper.getPathsToSelect(stringMap);
                result.put("paths", paths);
            } catch (Exception e) {
                logger.warn("获取路线用于查询失败");
                e.printStackTrace();

            }
        }


        return result;
    }

    @Override
    public void submitCourierData(Map<String, Object> stringMap) throws CustomException {
        //不用小云推送，因为小云id不确定，可以用大喇叭，店铺助手,通知是都通知还是，，，只要有一个没成功，都得重新通知
        String courierName = stringMap.get("courierName").toString();
        String assistName = stringMap.get("assistName").toString();
        String driverName = stringMap.get("driverName").toString();
        String licenseName = stringMap.get("licenseName").toString();
        String pathName = stringMap.get("pathName").toString();
        String time = stringMap.get("time").toString(); //配送时间


        // Calendar ca = Calendar.getInstance();
        // ca.setTime(new Date());
        // ca.add(Calendar.DATE, +1);
        // Date firstDay = ca.getTime();
        // SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        // String date = sf.format(firstDay);

        stringMap.put("deliveryTime", time);
        List<Integer> ids = shop2Mapper.getCourierData(stringMap);
        if (!ids.isEmpty()) {
            throw new CustomException(pathName + "路线已分配，请现撤销后再分配。");
        }

        String userInfo = "物流员：" + courierName + "。";
        if (StringUtils.isNot_NullOrTrimEmpty(assistName)) {
            userInfo += "\n协助物流员：" + assistName + "。";
        }
        if (StringUtils.isNot_NullOrTrimEmpty(driverName)) {
            userInfo += "\n驾驶员：" + driverName + "。";
        }
        String context1 = courierName + "你好：\n" + time + "配送线路已分配。\n路线 ：" + pathName + "。\n车辆：" + licenseName + "。\n" + userInfo;//+"合计订单金额，合计条数，共送多少家客户";
        String context2 = driverName + "你好：\n" + time + "配送线路已分配。\n路线 ：" + pathName + "。\n车辆：" + licenseName + "。\n" + userInfo;//+"合计订单金额，合计条数，共送多少家客户";
        String context3 = assistName + "你好：\n" + time + "配送线路已分配。\n路线 ：" + pathName + "。\n车辆：" + licenseName + "。\n" + userInfo;//+"合计订单金额，合计条数，共送多少家客户";

        try {
            stringMap.put("operatorTime", new Date());
            shop2Mapper.submitCourierData(stringMap);

            Emchat.sendTextMessage("-7", context1, stringMap.get("courier").toString(), null);
            if (StringUtils.isNot_NullOrTrimEmpty(stringMap.get("driver").toString()))
                Emchat.sendTextMessage("-7", context2, stringMap.get("driver").toString(), null);
            if (StringUtils.isNot_NullOrTrimEmpty(stringMap.get("assist").toString()))
                Emchat.sendTextMessage("-7", context3, stringMap.get("assist").toString(), null);
        } catch (Exception e) {
            throw new CustomException("通知失败,请重新提交");
        }

//        stringMap.put("operatorTime", new Date());
//        shop2Mapper.submitCourierData(stringMap);
    }

    @Override
    public PageDTO<Map<String, String>> getDeliveryPathList(Map<String, String> stringMap) {
        Integer pageSize = 10;
        Long page = stringMap.get("page") == null ? 1 : Long.valueOf(stringMap.get("page"));
        Long beginNum = ((page - 1) * pageSize + 1);
        Long endNum = beginNum + pageSize - 1;

        stringMap.put("beginNum", beginNum.toString());
        stringMap.put("endNum", endNum.toString());

        List<Map<String, String>> dataList;
        int recordCount;
        dataList = shop2Mapper.getDeliveryPathList(stringMap);
        recordCount = shop2Mapper.getDeliveryPathCount(stringMap);

        PageDTO<Map<String, String>> result = new PageDTO<>(page.intValue(), pageSize, dataList, recordCount);
        return result;
    }

    @Override
    public List<Map<String, String>> getQrCodeGenerate(Map<String, String> stringMap) {
        return shop2Mapper.getQrCodeGenerate(stringMap);
    }

    @Override
    public void revocationCourier(Map<String, String> params) throws CustomException {
        String courierName = params.get("COURIER");
        String assistName = params.get("ASSIST_COURIER");
        String driverName = params.get("DRIVER");
        String licenseName = params.get("LICENSE");
        String pathName = params.get("PATH");
        String deliveryTime = params.get("DELIVERY_TIME");

        String userInfo = "物流员：" + courierName + "。";
        if (StringUtils.isNot_NullOrTrimEmpty(assistName)) {
            userInfo += "\n协助物流员：" + assistName + "。";
        }
        if (StringUtils.isNot_NullOrTrimEmpty(driverName)) {
            userInfo += "\n驾驶员：" + driverName + "。";
        }
        String context1 = courierName + "你好：\n" + deliveryTime + "配送线路已撤销。\n路线 ：" + pathName + "。\n车辆：" + licenseName + "。\n" + userInfo;//+"合计订单金额，合计条数，共送多少家客户";
        String context2 = driverName + "你好：\n" + deliveryTime + "配送线路已撤销。\n路线 ：" + pathName + "。\n车辆：" + licenseName + "。\n" + userInfo;//+"合计订单金额，合计条数，共送多少家客户";
        String context3 = assistName + "你好：\n" + deliveryTime + "配送线路已撤销。\n路线 ：" + pathName + "。\n车辆：" + licenseName + "。\n" + userInfo;//+"合计订单金额，合计条数，共送多少家客户";

        try {
            shop2Mapper.revocationCourier(params);
            Emchat.sendTextMessage("-7", context1, params.get("COURIER_UID"), null);
            if (StringUtils.isNot_NullOrTrimEmpty(params.get("DRIVER_UID")))
                Emchat.sendTextMessage("-7", context2, params.get("DRIVER_UID"), null);
            if (StringUtils.isNot_NullOrTrimEmpty(params.get("ASSIST_COURIER_UID")))
                Emchat.sendTextMessage("-7", context3, params.get("ASSIST_COURIER_UID"), null);
        } catch (Exception e) {
            throw new CustomException("通知失败,请重新提交");
        }
//        shop2Mapper.revocationCourier(params);
    }

    @Override
    public List<Map<String, String>> selectDeliveryLineToSelected() {
        return shop2Mapper.selectDeliveryLineToSelected();
    }

    @Override
    public Double getAogQueryTotalPrice(Map<String, String> stringMap) {
        return shop2Mapper.getAogQueryTotalPrice(stringMap);
    }

    @Override
    public List<Map<String, String>> getRecommendOrderList(Map<String, String> stringMap) throws CustomException {

        Map<String, Object> params = new HashMap<>();
        params.putAll(stringMap);
        String cc = shop2Mapper.checkUserHasPrivilege(params);
        if (!stringMap.get("custCode").equals(cc)) {
            throw new CustomException("您没有操作客户" + stringMap.get("custCode") + "的权限");
        }

/*      String y = stringMap.get("year");
        String w = stringMap.get("week");

        if (StringUtils.isNot_NullOrTrimEmpty(y) && StringUtils.isNot_NullOrTrimEmpty(w)) {
            Date date;
            try {
                date = DateUtil.getThursdayByYearWeek(Integer.valueOf(y), Integer.valueOf(w));
            } catch (Exception e) {
                throw new CustomException("年周格式不对");
            }
            if (date == null) {
                throw new CustomException("年周解析出错（可能周数太大）");
            }
            stringMap.put("yearWeek", y + "-" + w);
            stringMap.put("yearMoth", new SimpleDateFormat("yyyy-MM").format(date));
        }*/

        return shop2Mapper.getRecommendOrderList(stringMap);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveRecommendData(String data, String year, String week, String custCode, Map<String, String> user) throws CustomException {

        JSONArray jsonArray = JSONArray.fromObject(data);
        List<Map<String, Object>> dataList = JSONArray.toList(jsonArray, new HashMap<>(), new JsonConfig());

        Map<String, Object> params = new HashMap<>();
        params.putAll(user);
        params.put("custCode", custCode);

        if (StringUtils.isNot_NullOrTrimEmpty(year) && StringUtils.isNot_NullOrTrimEmpty(week)) {

            String cc = shop2Mapper.checkUserHasPrivilege(params);
            if (!custCode.equals(cc)) {
                throw new CustomException("您没有操作客户" + custCode + "的权限");
            }

/*            Date date = DateUtil.getThursdayByYearWeek(Integer.valueOf(year), Integer.valueOf(week));
            if (date == null) {
                throw new CustomException("年周解析出错");
            }

            String yearWeek = year + "-" + week;
            String yearMoth = new SimpleDateFormat("yyyy-MM").format(date);*/

            for (Map<String, Object> da : dataList) {
                da.put("CUST_CODE", custCode);
                da.put("YEAR_WEEK", week);
                da.put("YEAR_MOTH", year);
            }
        }


        params.put("date", new Date());
        params.put("dataList", dataList);


        shop2Mapper.deleteRecommendByParams(params);
        shop2Mapper.insertRecommend(params);

        //System.out.println(dataList);
    }

    @Override
    public Map<String, Object> getRecommendCustAndProdData(Map<String, String> stringMap) {
        Map<String, Object> result = new HashMap<>();
        List<Map<String, String>> customers = shop2Mapper.getRecommendCustData(stringMap);
        List<Map<String, String>> prods = shop2Mapper.getRecommendProdsData(stringMap);
        result.put("customers", customers);
        result.put("prods", prods);
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addRecommendData(Map<String, String> stringMap) throws CustomException {
        Map<String, Object> params = new HashMap<>();
        params.putAll(stringMap);
        String cc = shop2Mapper.checkUserHasPrivilege(params);
        if (!stringMap.get("custCode").equals(cc)) {
            throw new CustomException("您没有操作客户" + stringMap.get("custCode") + "的权限");
        }

    /*    Date date = DateUtil.getThursdayByYearWeek(Integer.valueOf(stringMap.get("year")), Integer.valueOf(stringMap.get("week")));
        if (date == null) {
            throw new CustomException("年周解析出错");
        }
        params.put("yearWeek", stringMap.get("year") + "-" + stringMap.get("week"));
        params.put("yearMoth", new SimpleDateFormat("yyyy-MM").format(date));*/
        params.put("date", new Date());

        shop2Mapper.deleteRecommendByParam(params);
        shop2Mapper.insertRecommendOne(params);


    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addRecommendDataGR(Map<String, String> stringMap) {
        Map<String, Object> params = new HashMap<>();
        params.putAll(stringMap);
        params.put("date", new Date());
        shop2Mapper.deleteRecommendOrderGR(params);
        shop2Mapper.insertRecommendOrderGR(params);
    }

    @Override
    public List<Map<String, String>> getRecommendOrderGRList(Map<String, String> stringMap) {
        return shop2Mapper.getRecommendOrderGRList(stringMap);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateRecommendOrderGR(String data, Map<String, String> user) throws Exception {
        JSONArray jsonArray = JSONArray.fromObject(data);
        List<Map<String, Object>> dataList = JSONArray.toList(jsonArray, new HashMap<>(), new JsonConfig());

        for (Map<String, Object> da : dataList) {
            da.put("date", new Date());
            shop2Mapper.deleteRecommendOrderGR(da);
            shop2Mapper.insertRecommendOrderGR(da);
        }
    }

    @Override
    public PageDTO<Map<String, String>> getCust2ShopList(Map<String, String> stringMap) throws CustomException {
        Integer pageSize = 10;
        Long page = stringMap.get("page") == null ? 1 : Long.valueOf(stringMap.get("page"));
        Long beginNum = ((page - 1) * pageSize + 1);
        Long endNum = beginNum + pageSize - 1;

        stringMap.put("beginNum", beginNum.toString());
        stringMap.put("endNum", endNum.toString());

        List<Map<String, String>> dataList = null;
        int recordCount = 0;
        try {
            dataList = shop2Mapper.getCust2ShopListData(stringMap);
            recordCount = shop2Mapper.getCust2ShopListCount(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        PageDTO<Map<String, String>> result = new PageDTO<>(page.intValue(), pageSize, dataList, recordCount);
        return result;
    }

    @Override
    public List<Map<String, Object>> getCust2ShopListExportExcel(Map<String, String> stringMap) {
        return shop2Mapper.getCust2ShopListExportExcel(stringMap);
    }

    @Override
    public List<Map<String, Object>> getAogListExportExcel(Map<String, String> stringMap) {
        return shop2Mapper.getAogListExportExcel(stringMap);
    }

    @Override
    public PageDTO<Map<String, String>> getAogStatisticsListByPageQuery(Map<String, String> stringMap) throws CustomException {
        Integer pageSize = 10;
        Long page = stringMap.get("page") == null ? 1 : Long.valueOf(stringMap.get("page"));
        Long beginNum = ((page - 1) * pageSize + 1);
        Long endNum = beginNum + pageSize - 1;

        stringMap.put("beginNum", beginNum.toString());
        stringMap.put("endNum", endNum.toString());

        List<Map<String, String>> list = null;
        try {
            list = shop2Mapper.getAogStatisticsListByPageQuery(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("分页获取配送数据失败");
        }
        int recordCount = 0;
        try {
            recordCount = shop2Mapper.getAogStatisticsListCountByPageQuery(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("分页获取配送总数失败");
        }
        PageDTO<Map<String, String>> result = new PageDTO<>(page.intValue(), pageSize, list, recordCount);
        return result;
    }

    @Override
    public PageDTO<Map<String, String>> getDateMappingList(Map<String, String> stringMap) throws CustomException {
        Integer pageSize = 10;
        Long page = stringMap.get("page") == null ? 1 : Long.valueOf(stringMap.get("page"));
        Long beginNum = ((page - 1) * pageSize + 1);
        Long endNum = beginNum + pageSize - 1;

        stringMap.put("beginNum", beginNum.toString());
        stringMap.put("endNum", endNum.toString());

        List<Map<String, String>> dataList = null;
        int recordCount = 0;
        try {
            dataList = shop2Mapper.getDateMappingListData(stringMap);
            recordCount = shop2Mapper.getDateMappingListCount(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        PageDTO<Map<String, String>> result = new PageDTO<>(page.intValue(), pageSize, dataList, recordCount);
        return result;
    }

    @Override
    public void deleteDateMapping(Map<String, String> stringMap) {
        shop2Mapper.deleteDateMapping(stringMap);
    }

    @Override
    public void addDateMappingData(Map<String, String> stringMap) throws CustomException {
       String isNew =  stringMap.get("isNew");
       if ("1".equals(isNew)) {
           stringMap.put("beginNum", "1");
           stringMap.put("endNum", "1000");
           List<Map<String, String>> dataList = shop2Mapper.getDateMappingListData(stringMap);
           if (!dataList.isEmpty()) {
               throw new CustomException("年月周数据已存在");
           }
           //检查时间段是否已被用了
           List<Map<String, String>> data1 = shop2Mapper.checkDateIsUseForNew(stringMap);
           if (!data1.isEmpty()) {
               throw new CustomException("时间段已被使用");
           }

           shop2Mapper.insertDateMapping(stringMap);
       } else {
           //检查时间段是否已被用了
           List<Map<String, String>> data1 = shop2Mapper.checkDateIsUseForNew(stringMap);
           if (!data1.isEmpty()) {
               throw new CustomException("时间段已被使用");
           }
           shop2Mapper.updateDateMapping(stringMap);
       }

    }

    @Override
    public List<Map<String, String>> getWeekByYearMonth(String yearMonth) {
        return shop2Mapper.getWeekByYearMonth(yearMonth);
    }

    @Override
    public Map<String, String> getLastYearMonthWeek(String now) {
        return shop2Mapper.getLastYearMonthWeek(now);
    }

    @Override
    public String getNowWeek(String now) {
        return shop2Mapper.getNowWeek(now);
    }

    @Override
    public PageDTO<Map<String, String>> getRecommendStatisticsList(Map<String, String> stringMap) throws CustomException {
        Integer pageSize = 10;
        Long page = stringMap.get("page") == null ? 1 : Long.valueOf(stringMap.get("page"));
        Long beginNum = ((page - 1) * pageSize + 1);
        Long endNum = beginNum + pageSize - 1;

        stringMap.put("beginNum", beginNum.toString());
        stringMap.put("endNum", endNum.toString());

        List<Map<String, String>> dataList = null;
        int recordCount = 0;
        try {
            dataList = shop2Mapper.getRecommendStatisticsListData(stringMap);
            recordCount = shop2Mapper.getRecommendStatisticsListCount(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        PageDTO<Map<String, String>> result = new PageDTO<>(page.intValue(), pageSize, dataList, recordCount);
        return result;
    }

    @Override
    public Map<String, String> getAogStatisticsTotalByPageQuery(Map<String, String> stringMap) {
        return shop2Mapper.getAogStatisticsTotalByPageQuery(stringMap);
    }

    @Override
    public List<Map<String, Object>> getYearStockSale(Map<String, String> stringMap) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.YEAR,-1);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        String lastYear = simpleDateFormat.format(calendar.getTime()) +  "-01";
        stringMap.put("lastYear", lastYear);


        return null;
    }

    @Override
    public List<Map<String, Object>> getDateStockSale(Map<String, String> stringMap) {
        return null;
    }

    @Override
    public Map<String, String> getLogisticsTodayNums(Map<String, String> stringMap) {
        Map<String,String> pathAndCar =  shop2Mapper.getLogisticsPathAndCar(stringMap);
        //当天车辆和路线有数据，再去查询其它指标
        if (StringUtils.isNot_NullOrTrimEmpty(pathAndCar.get("PATH")) && !pathAndCar.get("PATH").equals("0")) {
            Map<String,String> customer = shop2Mapper.getCustAndOrder(stringMap);
            pathAndCar.putAll(customer);
            Map<String,String> finishCustomer = shop2Mapper.getFinishCustAndOrder(stringMap);
            pathAndCar.putAll(finishCustomer);

        }
        return pathAndCar;
    }

    @Override
    public List<Map<String, String>> getLogisticsYearStatistics(Map<String, String> stringMap) {
        return shop2Mapper.getLogisticsYearStatistics(stringMap);
    }

    @Override
    public List<Map<String, Object>> getIndustryGoYe(Map<String, String> stringMap) {
        return shop2Mapper.getIndustryGoYe(stringMap);
    }

    @Override
    public String getIndustryTotalQuantity(Map<String, String> stringMap) {
        Calendar cal = Calendar.getInstance();
        String year = String.valueOf(cal.get(Calendar.YEAR));
        stringMap.put("year", year);
        return shop2Mapper.getIndustryTotalQuantity(stringMap);
    }

    @Override
    public String getIndustryTotalShop(Map<String, String> stringMap) {
        return shop2Mapper.getIndustryTotalShop(stringMap);
    }

    @Override
    public String getIndustryTotalProductQ(Map<String, String> stringMap) {
        return null;
    }

    @Override
    public String getIndustryPlanQuantity(Map<String, String> stringMap) {
        return null;
    }

    @Override
    public List<Map<String, Object>> getIndustryShopLocation(Map<String, String> stringMap) {
        Calendar cal = Calendar.getInstance();
        String year = String.valueOf(cal.get(Calendar.YEAR));
        stringMap.put("year", year);
        return shop2Mapper.getIndustryShopLocation(stringMap);
    }

    @Override
    public List<Map<String, Object>> getGroupInfoData(Map<String, String> stringMap) throws CustomException {
        List<Map<String, Object>> dataList = null;
        try {
            dataList = shop2Mapper.getGroupInfoData(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        return dataList;
    }

    @Override
    public List<Map<String, Object>> getGroupMemberInfoData(Map<String, String> stringMap) throws CustomException {

        List<Map<String, Object>> dataList = null;
        String groupId = stringMap.get("groupId");
        if(groupId==null||"".equals(groupId)){
            throw new CustomException("服务器异常，获取数据失败");
        }
        try {
            dataList = shop2Mapper.getGroupMemberInfoData(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        return dataList;
    }

    @Override
    public List<Map<String, Object>> getMonopolys(Map<String, String> stringMap) throws CustomException {
        //获取营销数据
        List<Map<String, Object>> dataList = new ArrayList<>();
        try {
            dataList = shop2Mapper.getMonopolys(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        return dataList;
    }

    @Override
    public List<Map<String, Object>> getSalesData(Map<String, String> stringMap) throws CustomException {
        //获取营销数据
        List<Map<String, Object>> dataList = null;
        try {
            dataList = shop2Mapper.getSalesData(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        return dataList;
    }

    @Override
    public List<Map<String, Object>> getMemberLocal(Map<String, String> stringMap) throws CustomException {
        List<Map<String, Object>> dataList = null;
        try {
            dataList = shop2Mapper.getMemberLocal(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        return dataList;

    }

    @Override
    public List<Map<String, String>> getIndustryGoYeYearStatistics(Map<String, String> stringMap) {
        List<Map<String, String>> retList = new ArrayList<>();
        for(int i = 1; i <= 12; i ++){
            Map<String, String> map = new HashMap<>();
            String deliverDate = "";
            String time = "";
            if(i < 10){
                deliverDate = "20180" + i;
                time = "2018-0" + i;
            }else {
                deliverDate = "2018" + i;
                time = "2018-" + i;
            }
            map.put("deliverDate", deliverDate);
            map.put("time", time);
            Map<String, String> retMap = shop2Mapper.getIndustryGoYeYearStatistics(map);
            if(retMap != null) {
                retList.add(retMap);
            }
        }
        return retList;
    }

    @Override
    public List<Map<String, String>> getIndustryProductYearStatistics(Map<String, String> stringMap) {
        return null;
    }

    @Override
    public List<Map<String, Object>> getConstantlys(Map<String, String> stringMap) throws CustomException {
        //获取客户数据
        List<Map<String, Object>> dataList = new ArrayList<>();
        try {
            List<Map<String, Object>> list = shop2Mapper.getConstantlys(stringMap);
            if(list.size() > 0){
                for(int i = 0; i < list.size(); i++){
                    Map<String, String> retMap = new HashMap<>();
                    Map mapData = list.get(i);
                    String slsmanCode = mapData.get("CODE").toString();
                    retMap.put("slsmanCode",slsmanCode);
                    List<Map<String, Object>> shopList = shop2Mapper.gatShopInf(retMap);
//                    if(shopList.size() > 0) {
                        System.out.println(shopList);
//                    }
                    mapData.put("markeInfo", shopList);
                    dataList.add(mapData);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        return dataList;
    }

    @Override
    public List<Map<String, Object>> gatShopInf(Map<String, String> stringMap) throws CustomException {
        return null;
    }

    @Override
    public List<Map<String, Object>> getCustShopData(Map<String, String> stringMap) throws CustomException {
        //获取客户服务数据
        List<Map<String, Object>> dataList = new ArrayList<>();
        Map<String, Object> retData = new HashMap<>();
        try {
            List<Map<String, Object>> list = shop2Mapper.getCustShopData(stringMap);
            if(list.size() > 0){
                for(int i = 0; i < list.size(); i++) {
                    Map<String, String> retMap = new HashMap<>();
                    Map mapData = list.get(i);
                    retData.put("slsmanCode",stringMap.get("slsmanCode"));
                    List<Map<String, Object>> listTobaccoOrde =  countService.getTobaccoOrde(retData);
                    if(listTobaccoOrde.size() > 0) {
                        String shouldOrderUsers = listTobaccoOrde.get(0).get("SHOULD_CUST_CODE") == null ? "" : listTobaccoOrde.get(0).get("SHOULD_CUST_CODE").toString();
                        String alreadyOrderUsers = listTobaccoOrde.get(0).get("ALREADY_CUST_CODE") == null ? "" : listTobaccoOrde.get(0).get("ALREADY_CUST_CODE").toString();
                        String notOrderUsers = listTobaccoOrde.get(0).get("notOrderUsers") == null ? "" : listTobaccoOrde.get(0).get("notOrderUsers").toString();

                        String shouldKnotUsers = listTobaccoOrde.get(0).get("SUCCESS_CUST_CODE") == null ? "" : listTobaccoOrde.get(0).get("SUCCESS_CUST_CODE").toString();
                        String alreadyKnotUsers = listTobaccoOrde.get(0).get("CUST_CODE") == null ? "" : listTobaccoOrde.get(0).get("CUST_CODE").toString();
//                        String notKnotUsers = listTobaccoOrde.get(0).get("notOrderUsers") == null ? "" : listTobaccoOrde.get(0).get("notOrderUsers").toString();
                        mapData.put("shouldOrderUsers", shouldOrderUsers);
                        mapData.put("alreadyOrderUsers", alreadyOrderUsers);
                        mapData.put("notOrderUsers", notOrderUsers);
                        mapData.put("shouldKnotUsers", shouldKnotUsers);
                        mapData.put("alreadyKnotUsers", alreadyKnotUsers);
                    }

                    List<Map<String, Object>> shopList = shop2Mapper.gatShopInf(stringMap);
                    mapData.put("markeInfo", shopList);
                    dataList.add(mapData);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        return dataList;
    }

    @Override
    public List<Map<String, Object>> getMemberInfo(Map<String, String> stringMap) throws CustomException {
        List<Map<String, Object>> dataList = null;
        try {
            dataList = shop2Mapper.getMemberInfo(stringMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("服务器异常，获取数据失败");
        }
        return dataList;

    }
}
